import json
import typing
from typing import List
from logging import getLogger

from app.store.tg_api.dataclasses import UpdateObj

if typing.TYPE_CHECKING:
    from app.web.app import Application


class BotWorker:
    def __init__(self, app: "Application"):
        self.app = app
        self.logger = getLogger("handler")

    async def handle_update(self, body: dict):
        try:
            await self.app.store.tg_api.send_message(
                body["message"]["chat"]["id"],
                body["message"]["text"])
        except KeyError:
            try:
                await self.app.store.tg_api.send_document(
                    body["message"]["chat"]["id"],
                    body["message"]["document"]["file_id"])
            except Exception:
                await self.app.store.tg_api.send_message(
                    body["message"]["chat"]["id"],
                    "Не поддерживаемый тип файлов :(")
